home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 May / EnigmA AMIGA RUN 18 (1997)(G.R. Edizioni)(IT)[!][issue 1997-05][EAR-CD II].iso / softwareupdate / system / amigados / handlers / example1.c < prev    next >
C/C++ Source or Header  |  1996-10-10  |  7KB  |  174 lines

  1. /***********************************************************/
  2. /*                                                         */
  3. /* Amiga C Encyclopedia (ACE)           Amiga C Club (ACC) */
  4. /* --------------------------           ------------------ */
  5. /*                                                         */
  6. /* Manual:  AmigaDOS                    Amiga C Club       */
  7. /* Chapter: Handlers                    Tulevagen 22       */
  8. /* File:    Example1.c                  181 41  LIDINGO    */
  9. /* Author:  Anders Bjerin               SWEDEN             */
  10. /* Date:    93-03-16                                       */
  11. /* Version: 1.1                                            */
  12. /*                                                         */
  13. /*   Copyright 1993, Anders Bjerin - Amiga C Club (ACC)    */
  14. /*                                                         */
  15. /* Registered members may use this program freely in their */
  16. /*     own commercial/noncommercial programs/articles.     */
  17. /*                                                         */
  18. /***********************************************************/
  19.  
  20. /* This is an example on how to open a console window on the */
  21. /* default screen (usually the Workbench Screen). The window */
  22. /* will first be closed when the user clicks on the close    */
  23. /* gadget or types CTRL-\.                                   */
  24. /*                                                           */
  25. /* These types of console windows can be very handy when you */
  26. /* want to give the user some information. Console windows   */
  27. /* are easy to use and look good.                            */
  28. /*                                                           */
  29. /* This program uses some flags which are only available in  */
  30. /* dos library version 36 or higher. The program can however */
  31. /* still run on the older systems. The console window will   */
  32. /* then however be immediately closed when we close the      */
  33. /* file.                                                     */
  34.  
  35.  
  36.  
  37. /* Include the dos library definitions: */
  38. #include <dos/dos.h>
  39.  
  40. /* Now we include the necessary function prototype files:         */
  41. #include <clib/dos_protos.h>       /* General dos functions...    */
  42. #include <clib/exec_protos.h>      /* System functions...         */
  43. #include <stdio.h>                 /* Std functions [printf()...] */
  44. #include <stdlib.h>                /* Std functions [exit()...]   */
  45. #include <string.h>                /* Std functions [strlen()...] */
  46.  
  47.  
  48.  
  49. /* There are 10 lines of text we want to print: */
  50. #define NUMBER_LINES 10
  51.  
  52.  
  53.  
  54. /* Set name and version number: */
  55. UBYTE *version = "$VER: AmigaDOS/Handlers/Example1 1.1";
  56.  
  57.  
  58.  
  59. /* Declared our own function(s): */
  60.  
  61. /* Our main function: */
  62. int main( int argc, char *argv[] );
  63.  
  64.  
  65.  
  66. /* Main function: */
  67.  
  68. int main( int argc, char *argv[] )
  69. {
  70.   /* Some text we want to display: */
  71.   UBYTE *my_text[ NUMBER_LINES ] =
  72.   {
  73.     "The Amiga C Encyclopedia\nCopyright 1989-1993\nAnders Bjerin\n\n",
  74.     "An important message to all C programmers! The Amiga C Encyclopedia ",
  75.     "is shareware. If you use this manual or any other part in the ",
  76.     "Encyclopedia you MUST pay the registration fee! The fee is less ",
  77.     "than what a simple game cost, and a game may last two or three ",
  78.     "months at most while the Encyclopedia can give you years of fun ",
  79.     "and help!\n\nTo all honourable programmers who have already ",
  80.     "registered their copies I would like to send my best regards, ",
  81.     "and may the bugs be few...\n\n\t\tHappy Programming, ",
  82.     "\n\t\tAnders Bjerin\n\n(Only the Amiga makes it fun!)\n"
  83.   };
  84.  
  85.   /* A "BCPL" pointer to our console window: */
  86.   BPTR my_console;
  87.   
  88.   /* Store here the number of bytes actually written: */
  89.   long bytes_written;
  90.  
  91.   /* A simple loop variable: */
  92.   int loop; 
  93.  
  94.  
  95.   /* We will now open a console window on the default   */
  96.   /* (usually Workbench) screen. The window will have   */
  97.   /* the title "My Console", and there will be a close  */
  98.   /* gadget in the top left corner of the window. Since */
  99.   /* we also have set the flag "/WAIT" the window will  */
  100.   /* first be closed when the user clicks on the close  */
  101.   /* gadget or types CTRL-\.                            */
  102.   /*                                                    */
  103.   /* Please note that these flags are only available    */
  104.   /* in dos library V36 or higher. The program will     */
  105.   /* however still be able to run on the old versions   */
  106.   /* but there will not be any close gadget and the     */
  107.   /* window will close immediately when we close the    */
  108.   /* file.                                              */
  109.   my_console = 
  110.    Open( "CON:0/0/640/200/My Console/CLOSE/WAIT", MODE_NEWFILE );
  111.   
  112.   /* Have we opened the console successfully? */
  113.   if( my_console == NULL )
  114.   {
  115.     /* Inform the user: */
  116.     printf( "Error! Could not open the console window!\n" );
  117.  
  118.     /* Exit with an error code: */
  119.     exit( 20 );
  120.   }
  121.  
  122.  
  123.   /* Write all lines: */
  124.   for( loop = 0; loop < NUMBER_LINES; loop++ )
  125.   {
  126.     /* Write one line: */
  127.     bytes_written =
  128.       Write( my_console, my_text[ loop ], strlen( my_text[ loop ] ) );
  129.  
  130.     /* Could we write the complete line: */
  131.     if( bytes_written != strlen( my_text[ loop ] ) )
  132.     {
  133.       /* No! We could not write the whole line! */
  134.       printf( "Error! Could not write all text!\n" );
  135.  
  136.       /* Close the console window: */
  137.       Close( my_console );
  138.  
  139.       /* Exit with an error code: */
  140.       exit( 21 );
  141.     }
  142.   }
  143.  
  144.  
  145.  
  146.   /* Close the console window: */
  147.   Close( my_console );
  148.  
  149.   /* Note! Since we have opened a console window with a close */
  150.   /* gadget and set the flag "WAIT" the console window will   */
  151.   /* actually first be closed when the user clicks on the     */
  152.   /* close gadget or types "CTRL-\".                          */
  153.  
  154.   /* If the user has an old version of the dos library (before V36), */
  155.   /* the special flags will not work. The window will therefore      */
  156.   /* immediately be closed when you close the window, and there is   */
  157.   /* not any close gadget at the top left corner of the window.      */
  158.   /* Since the window will immediately be closed when we close the   */
  159.   /* file, it will be difficult for the user to read any message     */
  160.   /* before the window is closed. You should in such case try to     */
  161.   /* read some values from the console and ask the user to press     */
  162.   /* enter when he/she wants to close with window. The Read()        */
  163.   /* function will only return when the user has pressed enter, and  */
  164.   /* it can therefore be used to halt the execution. See next        */
  165.   /* example for more information on how to collect values from a    */
  166.   /* console window.                                                 */
  167.  
  168.  
  169.  
  170.   /* The End! */
  171.   exit( 0 );
  172. }
  173.                
  174.